const mongoose =  require('mongoose');

mongoose.connect("mongodb://127.0.0.1:27017/draw");

// Definition of Shcemas
const UserSchema = new mongoose.Schema({
            id : { type:Number},
            uid : { type: String, default: ''},
            uname : { type: String, default: ''},
            ugender : { type:Number},
            uaddress : { type: String, default: ''},
            ubalance : { type:Number},
            uavatar : { type: String, default: ''},
            skey : { type: String, default: ''},
            sessionkey : { type: String, default: ''},
            create_time: { type : Date, default: Date.now },
            update_time: { type : Date, default: Date.now }
        },{collection: 'user'}),

    CategorySchema = new mongoose.Schema({
        id : { type: String},
        name : { type: String, default: ''},
        color : { type: String, default: ''}
    },{collection: 'category'}),

    ImageSchema = new mongoose.Schema({
        favorited : {  type: Boolean },
        isLock : {  type: Boolean },
        name : {  type: String },
        figure : {  type: String },
        isnew : {  type: Boolean },
        price : { type: Number },
        isHot : {  type: Boolean },
        scenesImg : {  type: String },
        favoriteCount : {  type: Number },

        categoryId : {  type: String },
        pos : {  type: Number },
        animationName : {  type: String },
        colorImageList : {  type: String },
        steps : {  type: String },
        dashImg : {  type: String },

        id : {  type: String }
    },{collection: 'image'}),

    BannerSchema = new mongoose.Schema({
        isLock : {  type: Boolean },
        name : {  type: String },
        figure : {  type: String },
        color : {  type: String },
        price : { type: Number },
        imageId : {  type: String },
        deepLink : {  type: String },
        id : {  type: String }
    },{collection: 'banner'}),

    AnimationSchema = new mongoose.Schema({
        imageId : { type: String},
        context : { type: String}
    },{collection: 'animation'}),

    FavoriteSchema = new mongoose.Schema({
        uid : { type: String},
        imageId : { type: String}
    },{collection: 'favorite'}),

    AccessSchema = new mongoose.Schema({
        id : { type:Number},
        token : { type: String, default: ''},
        expires : { type:Number, default:0 }
    },{collection: 'access'});


const dbs = {},
    User = mongoose.model('User', UserSchema),
    Category = mongoose.model('Category', CategorySchema),
    Image = mongoose.model('Image', ImageSchema),
    Banner = mongoose.model('Banner', BannerSchema),
    Animation = mongoose.model('Animation', AnimationSchema),
    Favorite = mongoose.model('Favorite', FavoriteSchema),
    Access = mongoose.model('Access', AccessSchema);

dbs.user=User;
dbs.category=Category;
dbs.image=Image;
dbs.banner=Banner;
dbs.animation=Animation;
dbs.favorite=Favorite;
dbs.access=Access;

module.exports = dbs;
